package RobotPlayer
{
	import BasicEngine.Dispatcher;
	import DataStore.BmpDataPool;
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import GameLogic.Game;
	import SoundManager.SoundFactory;
	public class BaseExplode extends Sprite
	{
		private var main:Sprite;
		private var frame:Bitmap;
		private var bmps:Vector.<int>;
		private var timer:int;
		private var interval:int;
		private var index:int;
		private var duration:int;
		private var durationCount:int;
		
		/**
		 * _main:Sprite 容器 _a:Array BitmapData 索引 _interval:int 帧间隔时间 _duration:int 播放次数
		 */
		public function BaseExplode(_main:Sprite,_a:Array,_interval:int = 100,_duration:int = 1)
		{
			if(Game.SetButton.SettingPanel.turnoffSound.selected)
			    SoundFactory.Sounds["gun1"].play();
			main = _main;
			bmps = new Vector.<int>();
			frame = new Bitmap();
			addChild(frame);
			frame.x = -24;
			frame.y = -24;
			timer = 0;
			interval = _interval;
			index = 0;
			durationCount = _duration;
			duration = 0;
			for each(var i:int in _a)
			{
				bmps.push(i);
			}
			main.addChild(this);
			this.addEventListener(Event.ENTER_FRAME, Update);
		}
		
		private function Update(e:Event):void
		{
			if (Dispatcher.Clock.SystemTime - timer > interval)
			{
				if (index >= bmps.length)
				{
					index = 0;
					duration++;
				}
				if (duration < durationCount)
				{
					frame.bitmapData = BmpDataPool.WeaPool[bmps[index]];
					index++;
				}
				else
				{
					this.removeEventListener(Event.ENTER_FRAME, Update);
					frame = null;
					bmps = null;
					main.removeChild(this);
				}
				timer = Dispatcher.Clock.SystemTime;
			}
		}
	}
}